package ru.hashcode.hashdroid;

import android.app.Application;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.view.Display;
import android.view.Surface;
import android.view.WindowManager;

public class ResourcesHandler {
	private static Resources res = null;
	private static boolean land = false;
	
//	public static void setResources(Resources _res) {
//		res = _res;
//	}
	
	public static void setResources(Context _cnt) {
		res = _cnt.getResources();
		
		if (Build.VERSION.SDK_INT >= 8) {
			int rot_api8 = ((WindowManager) _cnt.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
			land = ((rot_api8 == Surface.ROTATION_90 ) || (rot_api8 == Surface.ROTATION_270 ));
		}
		else {
			int rot = ((WindowManager) _cnt.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getOrientation();
			land = rot == Configuration.ORIENTATION_LANDSCAPE;
		}
	}
	
	public static void setResources(Application _app) {
		res = _app.getResources();
		
	}
	
	public static Resources getResources() {
		if (res != null) return res;
		else throw new RuntimeException("ResourcesHandler not initialized");
	}
	
	public static boolean isLandscape() {
		return land;
	}	
	
}
